"""Definition of the app content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata

from Products.ePubBook import ePubBookMessageFactory as _
from Products.ePubBook.interfaces import IApp
from Products.ePubBook.config import PROJECTNAME


from Products.Archetypes.public import DisplayList
#from Products.Archetypes.public import *

# Local imports
#from Products.DataGridField import DataGridField, DataGridWidget
#from Products.DataGridField.Column import Column
#from Products.DataGridField.SelectColumn import SelectColumn

AppSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

    atapi.StringField(
        'copyright',
        required = True,
        widget=atapi.StringWidget(
            label=_(u"label_info_copyright",default=u'Copyright'),
            macro="my_string_widget"
        ),
    ),
    atapi.StringField(
        'keywords',
        required = True,
        widget=atapi.StringWidget(
            label=_(u"label_info_keywords",default=u'Keywords'),
            macro="my_string_widget"
        ),
    ),
    atapi.StringField(
        'price',
        required = True,
        vocabulary = '_getPrice',
        enforceVocabulary = 1,
        widget=atapi.SelectionWidget(
            label=_(u"label_info_price",default=u'Price'),
            macro="my_selection_widget"
        ),
    ),
    atapi.StringField(
        'primarycategory',
        required = True,
        vocabulary = '_getCategories',
        enforceVocabulary = 1,
        widget=atapi.SelectionWidget(
            label=_(u"label_info_primarycategory",default=u'Primary Category'),
            macro="my_selection_widget"
        ),
    ),
    atapi.StringField(
        'secondarycategory',
        required = True,
        vocabulary = '_getCategories',
        enforceVocabulary = 1,
        widget=atapi.SelectionWidget(
            label=_(u"label_info_secondarycategory",default=u'Secondary Category'),
            macro="my_selection_widget"
        ),
    ),
    atapi.StringField(
        'email',
         validators = ('isEmail',),
        widget=atapi.StringWidget(
            label=_(u"label_info_email",default=u'Email'),
            macro="my_string_widget"
        ),
    ),
    atapi.StringField(
        'supporturl',
        widget=atapi.StringWidget(
            label=_(u"label_info_supporturl",default=u'SupportURL'),
            macro="my_string_widget"
        ),
    ),
    atapi.StringField(
        'title_en',
        widget=atapi.StringWidget(
            label=_(u"label_info_title_en",default=u'Title'),
            macro="my_string_widget"
        ),
    ),
    atapi.StringField(
        'description_en',
        widget=atapi.TextAreaWidget(
            label=_(u"label_info_description_en",default=u'Description'),
            macro="my_textarea_widget"
        ),
    ),
    atapi.StringField(
        'keywords_en',
        widget=atapi.StringWidget(
            label=_(u"label_info_keywords_en",default=u'Keywords'),
            macro="my_string_widget"
        ),
    ),
    
    
    atapi.ImageField('introicon',
                    required = True,
                    default_output_type='image/jpeg',
                    allowable_content_types=('image/jpeg','image/png'),
                    sizes= {
                            'thumb'    : (108, 108),                            
                    },
                    widget = atapi.ImageWidget(
                        label = _(u'label_info_introicon',default = u'IntroIcon'),
                        description = _(u'help_info_introicon',default=u''),
                        macro="my_image_widget"
                    )
    ),
    atapi.ImageField('appicon',
                    required = True,
                    default_output_type='image/png',
                    allowable_content_types=('image/png'),
                    sizes= {
                            'thumb'    : (72, 72),                            
                    },
                    widget = atapi.ImageWidget(
                        label = _(u'label_info_appicon',default = u'AppIcon'),
                        description = _(u'help_info_appicon',default=u''),
                        macro="my_image_widget"
                    )
    ),
    atapi.BooleanField('issexual',
                       default=0,
                       widget = atapi.BooleanWidget(
                           label = _(u'label_info_issexual',default = u'Is sexual'),
                           description = _(u'help_info_issexual',default=u''),
                           macro="my_boolean_widget"
                       )
    ),
    atapi.BooleanField('isdrug',
                       default=0,
                       widget = atapi.BooleanWidget(
                           label = _(u'label_info_isdrug',default = u'Is drug'),
                           description = _(u'help_info_isdrug',default=u''),
                           macro="my_boolean_widget"
                       )
    ),
    atapi.ImageField('intropic1',
                       required=True,
                       default_output_type='image/jpeg',
                       allowable_content_types=('image/jpeg','image/png'),
                       sizes= {
                            'thumb'    : (138, 138),                            
                              },
                       widget = atapi.ImageWidget(
                           label = _(u'label_info_intropic',default = u'Introduce pictures'),
                           description = _(u'help_info_intropic',default=u''),
                           macro="my_image_widget"
                           
                    )
    ),
    atapi.ImageField('intropic2',
                       default_output_type='image/jpeg',
                       allowable_content_types=('image/jpeg','image/png'),
                       sizes= {
                            'thumb'    : (138, 138),                            
                              },
                       widget = atapi.ImageWidget(
                           label = _(u'label_info_intropic',default = u'Introduce pictures'),
                           description = _(u'help_info_intropic',default=u''),
                           macro="my_image_widget"
                    )
    ),
    atapi.ImageField('intropic3',
                       default_output_type='image/jpeg',
                       allowable_content_types=('image/jpeg','image/png'),
                       sizes= {
                            'thumb'    : (138, 138),                            
                              },
                       widget = atapi.ImageWidget(
                           label = _(u'label_info_intropic',default = u'Introduce pictures'),
                           description = _(u'help_info_intropic',default=u''),
                           macro="my_image_widget"
                    )
    ),
    atapi.ImageField('intropic4',
                       default_output_type='image/jpeg',
                       allowable_content_types=('image/jpeg','image/png'),
                       sizes= {
                            'thumb'    : (138, 138),                            
                              },
                       widget = atapi.ImageWidget(
                           label = _(u'label_info_intropic',default = u'Introduce pictures'),
                           description = _(u'help_info_intropic',default=u''),
                           macro="my_image_widget"
                    )
    ),
    atapi.ImageField('intropic5',
                       default_output_type='image/jpeg',
                       allowable_content_types=('image/jpeg','image/png'),
                       sizes= {
                            'thumb'    : (138, 138),                            
                              },
                       widget = atapi.ImageWidget(
                           label = _(u'label_info_intropic',default = u'Introduce pictures'),
                           description = _(u'help_info_intropic',default=u''),
                           macro="my_image_widget"
                    )
    ),
    
    
    
    atapi.StringField(
        'appleid',
        widget=atapi.StringWidget(
            label=_(u"label_info_appleid",default=u'Apple ID'),
        ),
    ),
    atapi.StringField(
        'appleurl',
        widget=atapi.StringWidget(
            label=_(u"label_info_appleurl",default=u'Apple Store URL'),
        ),
    ),
        
))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

AppSchema['description'].required = True
AppSchema['title'].widget.macro='my_string_widget'
AppSchema['description'].widget.macro = 'my_textarea_widget'

schemata.finalizeATCTSchema(AppSchema, moveDiscussion=False)


class App(base.ATCTContent):
    """Description of the Apple App"""
    implements(IApp)
    portal_type = 'App'
    archetype_name = 'App'
    meta_type = 'App'
    schema = AppSchema
    
    
    def _getPrice(self):
        return DisplayList((
            ('free', _(u'tier0',default=u'free')),
            ('$0.99', _(u'tier1',default=u'$0.99')),
            ('$1.99', _(u'tier2',default=u'$1.99')),
            ('$2.99', _(u'tier3',default=u'$2.99')),
            ('$3.99', _(u'tier3',default=u'$3.99')),
            ('$4.99', _(u'tier4',default=u'$4.99')),
            ('$5.99', _(u'tier5',default=u'$5.99')),
            ('$6.99', _(u'tier6',default=u'$6.99')),
            ('$7.99', _(u'tier7',default=u'$7.99')),
            ('$8.99', _(u'tier8',default=u'$8.99')),
            ('$9.99', _(u'tier9',default=u'$9.99'))
        ))
    def _getCategories(self):
        return DisplayList((
            ('Book', _(u'category_info_Book',default=u'Book')),
            ('Business', _(u'category_info_Business',default=u'Business')),
            ('Education', _(u'category_info_Education',default=u'Education')),
            ('Entertainment', _(u'category_info_Entertainment',default=u'Entertainment')),
            ('Finance', _(u'category_info_Finance',default=u'Finance')),
            ('Games', _(u'category_info_Games',default=u'Games')),
            ('HealthcareFitness', _(u'category_info_HealthcareFitness',default=u'Healthcare & Fitness')),
            ('Lifestyle', _(u'category_info_Lifestyle',default=u'Lifestyle')),
            ('Medical', _(u'category_info_Medical',default=u'Medical')),
            ('Music', _(u'category_info_Music',default=u'Music')),
            ('Navigation', _(u'category_info_Navigation',default=u'Navigation')),
            ('News', _(u'category_info_News',default=u'News')),
            ('Photography', _(u'category_info_Photography',default=u'Photography')),
            ('Productivity', _(u'category_info_Productivity',default=u'Productivity')),
            ('Reference', _(u'category_info_Reference',default=u'Reference')),
            ('SocialNetworking', _(u'category_info_SocialNetworking',default=u'Social Networking')),
            ('Sports', _(u'category_info_Sports',default=u'Sports')),
            ('Travel', _(u'category_info_Travel',default=u'Travel')),
            ('Utilities', _(u'category_info_Utilities',default=u'Utilities')),
            ('Weather', _(u'category_info_Weather',default=u'Weather'))
        )) 


atapi.registerType(App, PROJECTNAME)
